<template>
	<div></div>
</template>
<script>
import imchat from '../tool/imchat';
import { dateStr } from '../tool/tool';
export default {
	name: 'Message',
	/*im的业务数据处理，，邀请拍照，加入房间，，分享合同，，邀请手写签名*/
	methods: {
		/*发送消息的格式设置*/
		sendMessageFormat(message, type, url) {
			var data = {
				msgType: type,
				content: {
					message: message,
					url: url
				}
			};
			console.log('customer send message is', data);
			return data;
		},

		/*接受消息的格式设置*/
		receiveMessageDeal(data) {
			if (data.msgType === 'peer-status') {
				//交互场景，，加入房间，等等
				//{id: 'AgentId', status: 'joined’}
				if (data.content.message.status === 'joined') {
					imchat.$emit('joinroom');
					return 0;
				} else if (data.content.message.status === 'agenterror') {
					//坐席异常
					imchat.$emit('agenterror');
					return 0;
				} else if (data.content.message.status === 'transfer-agentleave') {
					//坐席转接后离开
					imchat.$emit('agentleave');
					return 0;
				} else if (data.content.message.status === 'transferagent-joined') {
					//坐席转接后离开,新的坐席加入成功
					imchat.$emit('transferagentjoined');
					return 0;
				}
			} else if (data.msgType === 'text') {
				// eslint-disable-next-line no-undef
				var text = textFace2imgFace(data.content.message);
				if (text.indexOf('info=') != -1) {
					//坐席帮访客填写的信息
					imchat.$emit('surecollectioninfo', text);
					return 0;
				}

				if (text.indexOf('sharelinkurl=') != -1) {
					//坐席帮访客填写的信息
					imchat.$emit('sharelinkurl', text);
					return 0;
				}

				if (text.indexOf('agentcollectionPic=') != -1) {
					//坐席帮访客填写的信息
					imchat.$emit('agentcollectionPic', text);
					return 0;
				}

				if (text.indexOf('sharevideourl=') != -1) {
					//坐席帮访客填写的信息
					imchat.$emit('sharevideourl', text);
					return 0;
				}

				if (text.indexOf('inputform') != -1) {
					//坐席发送表单给访客填写，，目前是默认一个模版的表单
					imchat.$emit('inputform');
					return 0;
				}

				if (text.indexOf('endsession') != -1) {
					//坐席结束会话
					imchat.$emit('exit');
					return 0;
				}
				if (text.indexOf('please handsign') != -1) {
					//手写签名
					console.log('agent tell you handsign');
					imchat.$emit('handsign');
					return 0;
				}
				if (text.indexOf('please snapshot') != -1) {
					//邀请访客拍照
					console.log('agent tell you snapshot');
					imchat.$emit('snapshot');
					return 0;
				}
				if (text.indexOf('please takephoto') != -1) {
					//这是坐席要求访客打开其他摄像头拍照
					imchat.$emit('takephoto');
					return 0;
				}

				if (text.indexOf('please screenshots') != -1) {
					//这是坐席要求访客screenshots
					imchat.$emit('screenshots');
					return 0;
				}

				if (text.indexOf('gotocontract') != -1) {
					imchat.$emit('gotocontract', data.content.url);
					return 0;
				}

				if (text.indexOf('http://') != -1) {
					//这是坐席要求访客提交表单
					imchat.$emit('gotoform', text + '&token=' + localStorage.getItem('customer_token'));
					text = '<a  target="_blank" href="' + text + '&token=' + localStorage.getItem('customer_token') + '">' + '信息采集,点击填写' + '</a>';
				}

				return {
					type: 'service',
					date: dateStr(),
					message: text
				};
			} else if (data.msgType === 'image') {
				// var text = textFace2imgFace(data.content.message);
				return {
					type: 'service',
					date: dateStr(),
					message: text,
					msgType: data.msgType
				};
			} else if (data.msgType === 'file') {
				// var text = textFace2imgFace(data.content.message);
				return {
					type: 'service',
					date: dateStr(),
					message: text,
					msgType: data.msgType,
					fileurl: data.content.url
				};
			}
			// else if(data.msgType === "contract"){
			//   //合同
			//   imchat.$emit("gotocontract",data.content.url);
			//   return 0;
			// }
			return 0;
		}
	}
};
</script>

<style scoped></style>
